﻿using System.Diagnostics;
using System.Threading;
using System.Web.Mvc;

namespace Filters.Infrastructure
{
    public class ProfileAllAttribute : ActionFilterAttribute
    {
        private Stopwatch _timer;

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            _timer = Stopwatch.StartNew();
        }

        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            _timer.Stop();
            filterContext.HttpContext.Response.Write(string.Format("<div> Total Time elapsed (ms) Action+Result: {0:F6}</div>", _timer.ElapsedMilliseconds));
        }
    }
}